package StudyCode.summary.BufferAndChannel;

import java.io.*;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class GetResourceReader {
	public static void main(String[] argv) throws IOException {
		Object caller = "www.tah1986.com";
		String resourceName = "www.tah1986.com";
		System.out.println(getResourceReader(caller, resourceName));
	}

	public static Reader getResourceReader(final Object caller, final String resourceName) throws IOException {
		BufferedReader in = null;
		try {
			InputStream stream = caller.getClass().getClassLoader().getResourceAsStream(resourceName);
			if (stream == null) {
				throw new java.lang.IllegalArgumentException("资源路径错误 " + resourceName);
			}
			in = new BufferedReader(new InputStreamReader(stream, "8859_1"));
		} catch (Exception i) {
			throw new java.io.IOException("读取资源失败: '" + resourceName + "'\n" + i.getMessage());
		}
		return in;
	}
}
